package com.example.pattern.observer.demo02;

import com.alibaba.fastjson.JSON;

import java.lang.reflect.Method;

public class Event {
    //事件源，事件是由谁发起的，保存起来
    private Object source;
    //事件触发，要通知谁
    private Object target;
    //事件触发，要做什么动作，回调
    private Method callback;
    //事件的名称，触发的是什么事件
    private String trigger;
    //事件触发的事件
    private long time;

    public Event(Object target, Method callback) {
        this.target = target;
        this.callback = callback;
    }

    public Event setSource(Object source) {
        this.source = source;
        return this;
    }

    public Event setTime(long time) {
        this.time = time;
        return this;
    }

    public Event setTrigger(String trigger) {
        this.trigger = trigger;
        return this;
    }

    public long getTime() {
        return this.time;
    }

    public Object getTarget() {
        return this.target;
    }

    public Method getCallback() {
        return this.callback;
    }

    public Object getSource() {
        return this.source;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
